package top.huxy.boot.model.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import top.huxy.boot.exception.RequestParamIllegalException;
import top.huxy.boot.util.StringUtils;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class DTOBlog {
    private Integer id;
    private String title;
    private String content;
    private String description;
    private String fm;
    private Boolean isTop;
    private Boolean isProtected;
    private Boolean appreciationAble;
    private Integer views;
    private Boolean isPrivate;
    private long createTime;
    private List<String> tags;
    private String password;
    private Boolean commentAble;
    private String cate;


    public void test() {
        String temp;
        if ((temp = StringUtils.getEmptyParamName("title, content,isTop,isProtected,appreciationAble,isPrivate,commentAble", title, content, isTop, isProtected, appreciationAble, isPrivate, commentAble)) != null) {
            throw new RequestParamIllegalException("缺少参数" + temp);
        }
        if (isPrivate && isProtected) {
            throw new RequestParamIllegalException("isPrivate && isProtected is true");
        }

        if (StringUtils.isEmpty(fm)) fm = null;
        if (isProtected) {
            if (StringUtils.isEmpty(password))
                throw new RequestParamIllegalException("when isProtected is true,password is required");
        } else {
            if (!StringUtils.isEmpty(password))
                throw new RequestParamIllegalException("when isProtected is false,password must be null or ''");
        }

        if (views == null || views < 0) {
            views = 0;
        }
    }
}